// orderFollow/pages/orderFollow/orderFollow.js
var common = require("../../../common/common.js").common;

Page({
    data: {
        latitude: "",
        longitude: "",
        markers: [ {
            id: 1,
            latitude: "",
            longitude: "",
            name: ""
        } ]
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let order_id = options.order_id;
        let that = this;
        common.request({
            endpoint: "Distribution/distribution/order-query",
            method: "post",
            data: {
                order_id: order_id
            },
            success: res => {
                console.log(res);
                that.setData({
                    name: res.extra.transporterName,
                    phone: res.extra.transporterPhone
                });
                if (res.extra.transporterLat && res.extra.transporterLng) {
                    let markers = [ {
                        id: 1,
                        latitude: res.extra.transporterLat,
                        longitude: res.extra.transporterLng,
                        name: ""
                    } ];
                    that.setData({
                        latitude: res.extra.transporterLat,
                        longitude: res.extra.transporterLng,
                        markers: markers
                    });
                } else {
                    let markers = [ {
                        id: 1,
                        latitude: res.extra.supplierLat,
                        longitude: res.extra.supplierLng,
                        name: ""
                    } ];
                    that.setData({
                        latitude: res.extra.supplierLat,
                        longitude: res.extra.supplierLng,
                        markers: markers
                    });
                }
            },
            fail: res => {
                wx.showModal({
                    title: "提示",
                    content: res.message,
                    success: res => {
                        wx.navigateBack();
                    }
                });
            }
        });
    },
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    // onPullDownRefresh: function () {
    // },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    onReady: function(e) {
        this.mapCtx = wx.createMapContext("myMap");
        console.log(this.mapCtx);
    },
    index_call() {
        wx.makePhoneCall({
            phoneNumber: this.data.phone
        });
    },
    getCenterLocation: function() {
        this.mapCtx.getCenterLocation({
            success: function(res) {
                console.log(res.longitude);
                console.log(res.latitude);
            }
        });
    },
    moveToLocation: function() {
        this.mapCtx.moveToLocation();
    },
    translateMarker: function() {
        this.mapCtx.translateMarker({
            markerId: 1,
            autoRotate: true,
            duration: 1e3,
            destination: {
                latitude: 23.10229,
                longitude: 113.3345211
            },
            animationEnd() {
                console.log("animation end");
            }
        });
    },
    includePoints: function() {
        this.mapCtx.includePoints({
            padding: [ 10 ],
            points: [ {
                latitude: 23.10229,
                longitude: 113.3345211
            }, {
                latitude: 23.00229,
                longitude: 113.3345211
            } ]
        });
    }
});